// 1.promise
const sleep = (time) => {
  return new Promise(resolve => setTimeout(resolve, time))
}
sleep(1000).then(() => {
  console.log(1)
})

// 2.async
function sleep1() {
  return new Promise(resolve => setInterval(resolve, time))
}
async function output() {
  let out = await sleep1();
  console.log(1);
  return out;
}
output()

// 3. ES5
function sleep2(callback, time) {
  if (typeof callback === 'function') {
    setTimeout(callback, time)
  }
}
function output2() {
  console.log(3)
}
sleep(output, 1000)

// 4. Generator
function* sleepGenerator(time) {
  yield new Promise(function (resolve, reject) {
    setTimeout(resolve, time);
  })
}
sleepGenerator(1000).next().value.then(() => { console.log(1) })
